package com.saic.data.main;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;

import com.saic.data.util.DBUtil;
import com.saic.data.util.HbaseUtil;
import com.saic.data.util.ZookeeperUtil;

/**
 * @DESC:创建HBASE表，一次性运行:创建表格/添加配置到Zookeeper上
 * @DESC:RUNNING ONLY ONCE
 * @author Xinshiyou
 */
public class AddTableInfo {

	/** 是否创建ORACLE TABLE **/
	private static final boolean flag = false;

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		List<String> list = new ArrayList<String>();
	    list.add("CF1");
		HbaseUtil.createTable("test_csv_tmp",list);
		HbaseUtil.createTable("test_csv_done",list);
		
		//CreateNodeAll();
		//CreateHbaseTable();
		//CreateOracleTable();
	}
	
	public static void CreateNodeAll() throws Exception {
		ZookeeperUtil zooUtil = new ZookeeperUtil();
		String jssap2 = "{\"col4\":\"AMOUNT\",\"col3\":\"ENTITY\",\"col6\":\"SOURCE_SYSTEM\",\"tmpHtbl\":\"sap2_csv_tmp\","
				+ "\"col5\":\"DAT_TIMESTAMP\",\"col0\":\"ACCOUNT\",\"col2\":\"PERIOD\",\"col1\":\"YEARS\",\"col8\":\"TARGET_APPLICATION\","
				+ "\"oracleTbl\":\"T_ETL_JCK_SAP_DAT_E\",\"col7\":\"TARGET_SYSTEM\",\"historyHtbl\":\"sap2_csv_done\",\"ftpDir\": \"sapuser2\",\"token\": \"\t\","
				+ "\"dstartPoint\": \"2\",\"dendPoint\": \"10\",\"dformat\": \"yyyyMMdd\",\"deleteflag\": \"true\"}";
		
		String jssap1 = "{\"col4\":\"AMOUNT\",\"col3\":\"ENTITY\",\"col6\":\"CUSTOM2\",\"tmpHtbl\":\"sap1_csv_tmp\","
				+ "\"col5\":\"CUSTOM4\",\"col0\":\"ACCOUNT\",\"col2\":\"PERIOD\",\"col1\":\"YEARS\",\"col10\":\"TARGET_APPLICATION\","
				+ "\"oracleTbl\":\"T_ETL_JCK_SAP_DAT_ECP\",\"col8\":\"SOURCE_SYSTEM\",\"col7\":\"DAT_TIMESTAMP\",\"historyHtbl\":\"sap1_csv_done\","
				+ "\"col9\":\"TARGET_SYSTEM\",\"ftpDir\": \"sapuser1\",\"token\": \"\t\","
				+ "\"dstartPoint\": \"2\",\"dendPoint\": \"10\",\"dformat\": \"yyyyMMdd\",\"deleteflag\": \"true\"}";
		
		String jsoazj = "{\"col4\":\"DAT_TIMESTAMP\",\"col3\":\"AMOUNT\",\"col6\":\"TARGET_SYSTEM\",\"tmpHtbl\":\"oazj_csv_tmp\","
				+ "\"col5\":\"SOURCE_SYSTEM\",\"col0\":\"ACCOUNT\",\"col2\":\"YEARS\",\"col1\":\"ENTITY\",\"oracleTbl\":\"T_ETL_JCK_OA_DAT_ZJ\","
				+ "\"col7\":\"TARGET_APPLICATION\",\"historyHtbl\":\"oazj_csv_done\",\"ftpDir\": \"oauser2\",\"token\": \"|\","
				+ "\"dstartPoint\": \"8\",\"dendPoint\": \"18\",\"dformat\": \"yyyy-MM-dd\",\"deleteflag\": \"false\"}";
		
		String jsoatz = "{\"col4\":\"DAT_TIMESTAMP\",\"col3\":\"AMOUNT\",\"col6\":\"TARGET_SYSTEM\",\"tmpHtbl\":\"oatz_csv_tmp\","
				+ "\"col5\":\"SOURCE_SYSTEM\",\"col0\":\"ACCOUNT\",\"col2\":\"YEARS\",\"col1\":\"ENTITY\",\"oracleTbl\":\"T_ETL_JCK_OA_DAT_TZ\","
				+ "\"col7\":\"TARGET_APPLICATION\",\"historyHtbl\":\"oatz_csv_done\",\"ftpDir\": \"oauser1\",\"token\": \"|\","
				+ "\"dstartPoint\": \"8\",\"dendPoint\": \"18\",\"dformat\": \"yyyy-MM-dd\",\"deleteflag\": \"false\"}";
		 
		zooUtil.add2ZK(zooUtil.rootpath+"/SAP2",jssap2);
		zooUtil.add2ZK(zooUtil.rootpath+"/SAP1",jssap1);
		zooUtil.add2ZK(zooUtil.rootpath+"/OAZJ",jsoazj);
		zooUtil.add2ZK(zooUtil.rootpath+"/OATZ",jsoatz);
		String content = zooUtil.getFromZK(zooUtil.rootpath+"/SAP2");
		JSONObject json = new JSONObject(content);
		System.out.println(json.toString());
		zooUtil.close();
		
	}
	@SuppressWarnings("static-access")
	public static void  CreateHbaseTable() throws Exception {
		/** create NAMESPACE */
		//HbaseUtil.createNameSpace(HbaseUtil.hbaseNameSpace);
		/** create tables */
		List<String> list = new ArrayList<String>();
	    list.add("CF1");
		HbaseUtil.createTable("ftp_file",list);
				
		ZookeeperUtil zooUtil = new ZookeeperUtil();
		JSONObject json;
	    String content;
	    Map<String,String> map =zooUtil.getProperties(zooUtil.rootpath);
	    
	    for(String key :map.keySet()){
	    content = map.get(key);
	    json = new JSONObject(content);
	     /*===========================================
	    List<String> list = TableConf.getColList(json);
	    
		list.add(Util.uuid);
		list.add(Util.fileName);
		list.add(Util.upLoadDate);
		list.add(Util.streamNo);
		==============================================*/
	    
		HbaseUtil.createTable(json.getString("tmpHtbl"), list);
		//list.add(Util.flag_check);
		HbaseUtil.createTable(json.getString("historyHtbl"), list);// TODO:添加标志字段
	    }
				
	}
	public static void CreateOracleTable() {
		if (flag) {
			DBUtil util = new DBUtil();
			util.execute("drop table T_ETL_JCK_OA_DAT_TZ");
			util.execute("drop table T_ETL_JCK_OA_DAT_ZJ");
			util.execute("drop table T_ETL_JCK_SAP_DAT_ECP");
			util.execute("drop table T_ETL_JCK_SAP_DAT_E");
			util.execute("create table T_ETL_JCK_OA_DAT_TZ(SOURCE_SYSTEM	 	VARCHAR(80),SOURCE_APPLICATION	 	VARCHAR(80),TARGET_SYSTEM	 	VARCHAR(80),TARGET_APPLICATION	 	VARCHAR(80),ID	 	VARCHAR(80),ENTITY	 	VARCHAR(80),ACCOUNT	 	VARCHAR(80),YEAR	 	VARCHAR(80),PERIOD	 	VARCHAR(80),CUSTOM1	 	VARCHAR(80),CUSTOM2	 	VARCHAR(80),CUSTOM3	 	VARCHAR(80),CUSTOM4	 	VARCHAR(80),CUSTOM5	 	VARCHAR(80),CUSTOM6	 	VARCHAR(80),CUSTOM7	 	VARCHAR(80),CUSTOM8	 	VARCHAR(80),CUSTOM9	 	VARCHAR(80),CUSTOM10	 	VARCHAR(80),CUSTOM11	 	VARCHAR(80),CUSTOM12	 	VARCHAR(80),CUSTOM13	 	VARCHAR(80),CUSTOM14	 	VARCHAR(80),CUSTOM15	 	VARCHAR(80),CUSTOM16	 	VARCHAR(80),CUSTOM17	 	VARCHAR(80),CUSTOM18	 	VARCHAR(80),CUSTOM19	 	VARCHAR(80),CUSTOM20	 	VARCHAR(80),AMOUNT	 	float not null,DETAIL	 	VARCHAR(80),DAT_TIMESTAMP	 	VARCHAR(80))");
			util.execute("create table T_ETL_JCK_OA_DAT_ZJ(SOURCE_SYSTEM	 	VARCHAR(80),SOURCE_APPLICATION	 	VARCHAR(80),TARGET_SYSTEM	 	VARCHAR(80),TARGET_APPLICATION	 	VARCHAR(80),ID	 	VARCHAR(80),ENTITY	 	VARCHAR(80),ACCOUNT	 	VARCHAR(80),YEAR	 	VARCHAR(80),PERIOD	 	VARCHAR(80),CUSTOM1	 	VARCHAR(80),CUSTOM2	 	VARCHAR(80),CUSTOM3	 	VARCHAR(80),CUSTOM4	 	VARCHAR(80),CUSTOM5	 	VARCHAR(80),CUSTOM6	 	VARCHAR(80),CUSTOM7	 	VARCHAR(80),CUSTOM8	 	VARCHAR(80),CUSTOM9	 	VARCHAR(80),CUSTOM10	 	VARCHAR(80),CUSTOM11	 	VARCHAR(80),CUSTOM12	 	VARCHAR(80),CUSTOM13	 	VARCHAR(80),CUSTOM14	 	VARCHAR(80),CUSTOM15	 	VARCHAR(80),CUSTOM16	 	VARCHAR(80),CUSTOM18	 	VARCHAR(80),CUSTOM19	 	VARCHAR(80),CUSTOM20	 	VARCHAR(80),AMOUNT	 	float not null,DETAIL	 	VARCHAR(80),DAT_TIMESTAMP	 	VARCHAR(80))");
			util.execute("create table T_ETL_JCK_SAP_DAT_ECP(SOURCE_SYSTEM	 	VARCHAR(80),SOURCE_APPLICATION	 	VARCHAR(80),TARGET_SYSTEM	 	VARCHAR(80),TARGET_APPLICATION	 	VARCHAR(80),REPORT	 	VARCHAR(80),ENTITY	 	VARCHAR(80),ACCOUNT	 	VARCHAR(80),YEAR	 	VARCHAR(80),PERIOD	 	VARCHAR(80),CUSTOM1	 	VARCHAR(80),CUSTOM2	 	VARCHAR(80),CUSTOM3	 	VARCHAR(80),CUSTOM4	 	VARCHAR(80),CUSTOM5	 	VARCHAR(80),CUSTOM6	 	VARCHAR(80),CUSTOM7	 	VARCHAR(80),CUSTOM8	 	VARCHAR(80),CUSTOM9	 	VARCHAR(80),CUSTOM10	 	VARCHAR(80),CUSTOM11	 	VARCHAR(80),CUSTOM12	 	VARCHAR(80),CUSTOM13	 	VARCHAR(80),CUSTOM14	 	VARCHAR(80),CUSTOM15	 	VARCHAR(80),CUSTOM16	 	VARCHAR(80),CUSTOM17	 	VARCHAR(80),CUSTOM18	 	VARCHAR(80),CUSTOM19	 	VARCHAR(80),CUSTOM20	 	VARCHAR(80),AMOUNT	 	float not null,DETAIL	 	VARCHAR(80),DAT_TIMESTAMP	 	VARCHAR(80))");
			util.execute("create table T_ETL_JCK_SAP_DAT_E(SOURCE_SYSTEM	 	VARCHAR(80),SOURCE_APPLICATION	 	VARCHAR(80),TARGET_SYSTEM	 	VARCHAR(80),TARGET_APPLICATION	 	VARCHAR(80),REPORT	 	VARCHAR(80),ENTITY	 	VARCHAR(80),ACCOUNT	 	VARCHAR(80),YEAR	 	VARCHAR(80),PERIOD	 	VARCHAR(80),CUSTOM1	 	VARCHAR(80),CUSTOM2	 	VARCHAR(80),CUSTOM3	 	VARCHAR(80),CUSTOM4	 	VARCHAR(80),CUSTOM5	 	VARCHAR(80),CUSTOM6	 	VARCHAR(80),CUSTOM7	 	VARCHAR(80),CUSTOM8	 	VARCHAR(80),CUSTOM9	 	VARCHAR(80),CUSTOM10	 	VARCHAR(80),CUSTOM11	 	VARCHAR(80),CUSTOM12	 	VARCHAR(80),CUSTOM13	 	VARCHAR(80),CUSTOM14	 	VARCHAR(80),CUSTOM15	 	VARCHAR(80),CUSTOM16	 	VARCHAR(80),CUSTOM17	 	VARCHAR(80),CUSTOM18	 	VARCHAR(80),CUSTOM19	 	VARCHAR(80),CUSTOM20	 	VARCHAR(80),AMOUNT	 	float not null,DETAIL	 	VARCHAR(80),DAT_TIMESTAMP	 	VARCHAR(80))");
		}
		
	}
	
}
